﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hive.Core;

namespace Hive.Bot.Tasks
{
    public class GatherTask: MoveTask
    {
        int[,] calculation;

        public GatherTask(Location destination, int[,] calculation)
            : base(destination)
        {
            this.calculation = calculation;
            //Log.LogPathCalculation(calculation);
        }

        public override IEnumerable<int> CalculateEfficiencies(IEnumerable<Ant> ants)
        {
            return ants.Select(a => GetEfficiencyByDistance(calculation.At(a.Location)));
        }

        public override Order Execute()
        {
            if (calculation.At(ant.Location) <= 1)
            {
                return new Order()
                {
                    Ant = ant,
                    Destination = ant.Location,
                    Efficiency = 100
                };
            }
            else
            {
                var route = Env.Map.BuildPath(calculation, ant.Location, destination);
                return GetOrderByRoute(route);
            }
        }

        public override string ToString()
        {
            return string.Format("Gather food at {0}", destination);
        }
    }
}
